﻿
using BestTrader.Cms.ViewModels;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BestTrader.Cms.Core.Extensions;

namespace BestTrader.Cms.Admin.Validation
{
    public class ManagerTerminalRegisterValidation : AbstractValidator<ManagerTerminalRegisterModel>
    {
        public ManagerTerminalRegisterValidation()
        {
            //RuleFor(x => x.UserName).NotEmpty().Length(5, 32).WithMessage("用户名不能为空并且长度不能超过16个字符");
            RuleFor(x => x.RealName).NotEmpty().Length(2, 10).WithMessage("姓名不能为空并且长度不能超过10个字符");
            RuleFor(x => x.UID).NotEmpty().WithMessage("代理编号不能为空");
            RuleFor(x => x.Reg).NotEmpty().WithMessage("注册码不能为空");
            //RuleFor(x => x.RoleId).NotNull().WithMessage("用户所属角色不能为空") ;
            //RuleFor(x => x.NickName).Length(1,32).WithMessage("用户昵称长度不能超过32个字符") ;
            RuleFor(x => x.Mobile).Must(IsMobile).WithMessage("手机号码格式不正确");
            RuleFor(x => x.BankCard).NotNull().WithMessage("用户银行卡号不能为空");
            RuleFor(x => x.Email).NotNull().WithMessage("邮箱不能为空");
            RuleFor(x => x.AuditImages).NotNull().WithMessage("用户图片资料不能为空");
        }

        private bool IsEmail(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsEmail())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private bool IsMobile(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsMobileNumber())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
